<?php
/**
 * CreateTime: 2023/1/10 16:38
 */

namespace App\Models;

use App\Consts\BaseConsts\BaseConsts;
use App\Scopes\MediationStaffScope;


class BaseModelAdminV1 extends BaseModel
{
    /**
     * 注册全局作用域
     */
    protected static function booted()
    {
        // static::addGlobalScope(new MediationStaffScope());
    }

    /**
     * 新增数据 返回id
     * @param $data
     * @return mixed
     */
    public function add($data){
        return $this->insertGetId($data);
    }

    /**
     * 通过组件更新数据
     * @param $data
     * @return mixed
     */
    public function updateData($data){
        return $this->where($this->primaryKey,$data[$this->primaryKey])->update($data);
    }

    /**
     * 获取有状态的详情
     * @param $id
     * @param string[] $select
     * @return mixed
     */
    public function getById($id,$select = ["*"]){
        return $this->select($select)
            ->where($this->primaryKey,$id)
            ->where('status',BaseConsts::STATUS_NORMAL)
            ->first();
    }

    public function getInfoByHash($hash,$select = ["*"]){
        return $this->select($select)
            ->where('pdf_path_hash',$hash)
            ->first();
    }

    public function getAllById($id,$select = ["*"]){
        return $this->select($select)
            ->where($this->primaryKey,$id)
            ->first();
    }

    public function getList($query,$pageSize): mixed
    {
        return $query->where('status',BaseConsts::STATUS_NORMAL)
            ->latest()
            ->Paginate($pageSize);
    }

    public function getListNoTime($query,$pageSize): mixed
    {
        return $query->where('status',BaseConsts::STATUS_NORMAL)
            ->orderBy($this->primaryKey,'DESC')
            ->Paginate($pageSize);
    }

    public function getListNoTimeNotStatus($query,$pageSize): mixed
    {
        return $query
            ->orderBy($this->primaryKey,'DESC')
            ->Paginate($pageSize);
    }
}